package com.apes.framework.config.dozer;

import com.apes.framework.util.bean.compiler.DynamicEngine;
import org.apache.commons.lang3.ClassUtils;
import org.dozer.util.DozerClassLoader;
import org.dozer.util.MappingUtils;
import org.dozer.util.ResourceLoader;

import java.net.URL;

/**
 * 功能：
 *
 * @author xul
 * @create 2018-11-20 16:35
 */
public class ApesDozerClassLoader implements DozerClassLoader {
    private final ResourceLoader resourceLoader = new ResourceLoader();

    public ApesDozerClassLoader() {
    }

    @Override
    public Class<?> loadClass(String className) {
        Class result = null;

        try {
            result = ClassUtils.getClass(className);
        } catch (ClassNotFoundException e) {
            try {
                result = DynamicEngine.getInstance().getLoader().loadClass(className);
            } catch (ClassNotFoundException e1) {
                MappingUtils.throwMappingException(e1);
            }
        }
        return result;
    }

    @Override
    public URL loadResource(String uri) {
        return this.resourceLoader.getResource(uri);
    }
}
